package com.project.controller;

import com.github.pagehelper.PageInfo;
import com.project.bean.SellBean;
import com.project.bean.SellCarBean;
import com.project.bean.UserBean;
import com.project.service.ISellService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.Map;

@Controller
@RequestMapping("sell")
public class SellController {
    @Autowired
    private ISellService service;

    //出库
@RequestMapping("/add")
@ResponseBody
    public String add(SellBean sell, HttpServletRequest request){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        Map<Integer,SellCarBean> sellCarMap = (Map<Integer, SellCarBean>) request.getSession().getAttribute("sellCarMap");
        service.add(sell, sellCarMap);
        return "ok";
    }

    @RequestMapping("/item")
    @ResponseBody
    public PageInfo<SellBean> findByItem(int pageNO, String name, LocalDate startDate, LocalDate endDate){
        return service.findByItem(pageNO,name,startDate,endDate);
    }
    @RequestMapping("/id")
    @ResponseBody
    public SellBean findById(int sellId) {
        return service.findById(sellId);
    }

}
